﻿using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace NDK.Motion.Sys
{
    /// <summary>
    /// 系统状态定义
    /// </summary>
    public enum MachineStatus
    {
        /// <summary>
        /// 未知状态，松开急停按钮后，软件刚启动等
        /// </summary>
        [Description("未知状态")]
        Unknown,

        /// <summary>
        /// (板卡，量测源等)初始化完成状态
        /// </summary>
        [Description("初始化完成")]
        Initialized,

        /// <summary>
        /// 运行状态
        /// </summary>
        [Description("运行状态")]
        Running,

        /// <summary>
        /// 暂停状态
        /// </summary>
        [Description("暂停状态")]
        Pause,

        /// <summary>
        /// 复位中
        /// </summary>
        [Description("复位中")]
        Homing,

        /// <summary>
        /// 复位完成
        /// </summary>
        [Description("复位完成")]
        Ready,

        /// <summary>
        /// 急停状态
        /// </summary>
        [Description("急停状态")]
        Emerg,

        /// <summary>
        /// 报警状态
        /// </summary>
        [Description("报警状态")]
        Alarm,

        /// <summary>
        /// 停止中
        /// </summary>
        [Description("停止中")]
        Stopping,

        /// <summary>
        /// 退出状态
        /// </summary>
        [Description("退出状态")]
        Quit,

        Manual,

        Auto
    }

    public static class MachineStatusManager
    {
        /// <summary>
        /// 当前状态
        /// </summary>
        private static MachineStatus _currentMachineStatus = MachineStatus.Unknown;
        public static event PropertyChangedEventHandler PropertyChanged;
        public static MachineStatus CurrentMachineStatus
        {
            get
            {
                return _currentMachineStatus;
            }

            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (_currentMachineStatus != value)
                {
                    _lastMachineStatus = _currentMachineStatus;
                    _currentMachineStatus = value;
                    PropertyChanged?.BeginInvoke("MachineStatusManager", new PropertyChangedEventArgs(value.ToString()), null, null);
                }
            }
        }

        /// <summary>
        /// 上一次的状态
        /// </summary>
        private static MachineStatus _lastMachineStatus = MachineStatus.Unknown;
        public static MachineStatus LastMachineStatus
        {
            get
            {
                return _lastMachineStatus;
            }
        }


    }

}
